<?php

namespace Home\Controller;

use Think\Controller;

class CommentController extends Controller {

    //添加评论
    public function addComment() {
        $comment = D('comment');
        $article = D('article');
        $data = I('post.');
        //文章id
        $id = I('post.a_id');
        // var_dump($id);die;
        // 评论总数
        $count = $comment->where('a_id=' . $id)->count();
        // var_dump($count);die;
        $res['comment_num'] = $count + 1;
        $article->where('id=' . $id)->save($res);
        $data['comment_time'] = date('Y-m-d H:i:s', time());
        if ($comment->create($data) && $comment->add()) {
        	// var_dump($id);die;
            $this->redirect(U('Home/index/lists', ['id' => $id]));
        } else {
            $this->error($comment->getError());
        }


        // var_dump($data);
    }

}
